<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">
            <el-form-item label="品牌名" prop="name">
                <el-input v-model="form.name"></el-input>
        	</el-form-item>
            <el-form-item label="资质图" prop="images">
                <sc-upload-multiple v-model="form.images"></sc-upload-multiple>
        	</el-form-item>
            <!-- <el-form-item label="店铺" prop="">
                <el-input disabled value="{{store_id_option[form.store_id]}}"></el-input>
        	</el-form-item> -->

            <el-form-item label="店铺" prop="">
                <el-select v-model="form.store_id" clearable placeholder="店铺" disabled>
                    <el-option   v-for="(item,index) in store_id_option" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

            <!-- <el-form-item label="上传时间" prop="createtime">
                <el-date-picker v-model="form.createtime" type="datetime" ></el-date-picker>
        	</el-form-item> -->
            <el-form-item label="状态" prop="status">
                <el-radio v-model="form.status" v-for="(item,index) in status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>

            <el-form-item label="拒绝理由" prop="ps" v-if="form.status=='3'">
                <el-input  v-model="form.ps"></el-input>
        	</el-form-item>


        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					images: '',
					store_id: '',
					createtime: '',
					status: '',
                },
                rules: {
                },
				status_option:{"1":"待审核","2":"已通过","3":"已拒绝"},
                store_id_option:[],
            }
        },
        mounted() {
            this.getStore();
        },
        methods: {
            async getStore(){
                
                var res = await this.$API.store.read.get();
                this.store_id_option =  res.data.list;
            },
            open(mode='create'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.goodsbrand_apply[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){

                this.$TABLE.assign(this,data);
            }
        }
    }
</script>